<template>
  <common-list>
    <common-table
      v-loading="loading"
      slot="content"
      :data="list"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        label="名称"
        align="left"
        prop="assessName"
        width="250"
        show-overflow-tooltip
      />
      <el-table-column
        label="模型配置"
        align="left"
        prop="config"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          敏感分类({{ scope.row.typeTotal || 0 }}%)：{{ scope.row.resultType
          }}{{ scope.row.resultTag }}{{ scope.row.resultCore
          }}{{ scope.row.resultSensitive }}<br />
          脆弱性({{ scope.row.weak || 0 }}%)：{{ scope.row.resultWeak }}<br />
          基线异常({{ scope.row.baseLine || 0 }}%)：{{ scope.row.resultLine
          }}<br />
          异常访问({{ scope.row.execVisit || 0 }}%)：{{ scope.row.resultVisit
          }}<br />
          OWASP风险({{ scope.row.risk || 0 }}%)：{{ scope.row.resultRisk }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="left" width="100px">
        <template slot-scope="scope">
          <el-button type="text" @click="handleDetail(scope.row)"
            >详情
          </el-button>
          <el-button type="text" @click="handleEdit(scope.row)"
            >编辑
          </el-button>
        </template>
      </el-table-column>
    </common-table>

    <pagination
      slot="pagination"
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <model-edit
      ref="modelEdit"
      v-if="isShowModelEdit"
      :isEdit="isEdit"
      :currentId="currentId"
      @close="closeDialog"
      @submitForm="submitForm"
    ></model-edit>
  </common-list>
</template>

<script>
import {
  fetchList,
  fetchDetail,
  modelEdit,
} from "@/api/apisecurity/model/model";
import ModelEdit from "./components/modelEdit.vue";
import BaseList from "@/mixins/BaseList";
export default {
  mixins: [BaseList],
  components: {
    ModelEdit,
  },
  data() {
    return {
      ids: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
      list: [],
      loading: false,
      isEdit: false,
      isShowModelEdit: false,
      currentId: "",
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      fetchList(this.queryParams)
        .then((res) => {
          if (res && res.code === 200) {
            this.list = res.rows;

            this.total = res.total;
          } else {
            this.list = [];
            this.total = 0;
            this.handleListTips(res);
          }
        })
        .catch(() => {
          this.list = [];
          this.total = 0;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    submitForm() {
      this.isShowModelEdit = false;
      this.getList();
    },

    handleEdit(row) {
      this.isEdit = true;
      this.currentId = row.id;
      this.isShowModelEdit = true;
    },

    handleDetail(row) {
      this.isEdit = false;
      this.currentId = row.id;
      this.isShowModelEdit = true;
    },

    closeDialog() {
      this.isShowModelEdit = false;
    },
  },
};
</script>

<style lang="scss"></style>
